package com.example;

import com.example.constant.GeoType;
import com.example.domain.NameModel;
import com.example.domain.PathModel;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/8/2<br/>
 *
 * @author QiuYang
 */
@Path("myresource")
public class MyResource {
//    @GET
//    @Produces(MediaType.TEXT_PLAIN)
//    public String getIt(){
//        return "Got it!";
//    }

    @GET
    @Path("geotype")
    @Produces(MediaType.TEXT_PLAIN)
    public String getGeotype(@QueryParam("geoType") @DefaultValue("POINT") GeoType geoType){
        return geoType.name();
    }


    @POST
    @Path("{path}/1")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response getPath(PathModel pathModel){
        String p = pathModel.getPath();
        boolean use = pathModel.isUse();
        return Response.ok(p + use).build();
    }

    @POST
    @Path("1")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test1(NameModel model){
        StringBuilder builder = new StringBuilder();
        model.getNames().forEach(name -> builder.append(name.getName() + " "));
        return Response.ok(builder.toString()).build();
    }
}
